                                                                     
                                                                     
                                                                     
                                             
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.65])
AC_INIT([drinkduinogame], [0.1], [craig@gfxhax.com],[drinkduinogame],[http://www.gfxhax.com/])
AC_CONFIG_AUX_DIR([config])
AC_CONFIG_MACRO_DIR([config])
AM_INIT_AUTOMAKE([foreign])
AC_CONFIG_SRCDIR([src/drinkduino.cpp])
AC_CONFIG_HEADERS([config.h])

# Set the proper prefix
AS_IF([test "$prefix" = "NONE"], [
  prefix="$ac_default_prefix"
])
AS_IF([test "$exec_prefix" = "NONE"], [
  exec_prefix="$prefix"
])

# Checks for programs.
AC_PROG_CXX

# Checks for libraries.
AC_CHECK_LIB([SDL], [SDL_Init])
AC_CHECK_LIB([SDL_image], [IMG_Load])
AC_CHECK_LIB([SDL_ttf], [TTF_RenderText_Blended])
AC_CHECK_LIB([SDL_gfx], [zoomSurface])
AC_CHECK_LIB([sqlite3], [sqlite3_prepare])
AC_CHECK_LIB([cv], [cvResize])
AC_CHECK_LIB([highgui], [cvCreateCameraCapture])
AX_LIB_SQLITE3(3.5.9)
AM_PATH_SDL([1.2.0], [], [
  AC_ERROR([SDL not found])
])

# Checks for header files.
AC_CHECK_HEADER([SDL/SDL_rotozoom.h], [], [AC_MSG_ERROR([Missing SDL_rotozoom.  Please install libsdl-gfx1.2-dev])])
AC_CHECK_HEADER([opencv/cv.h], [], [AC_MSG_ERROR([Missing OpenCV headers.  Please install libcv-dev])])
AC_CHECK_HEADER([opencv/highgui.h], [], [AC_MSG_ERROR([Missing OpenCV HighGUI headers.  Please install libhighgui-dev])])
AC_CHECK_HEADER([sqlite3.h], [], [AC_MSG_ERROR([Missing SQLite3 headers.  Please install libsqlite3-dev])])
AC_CHECK_HEADERS([fcntl.h stdlib.h string.h sys/ioctl.h termios.h unistd.h])

# Checks for typedefs, structures, and compiler characteristics.

# Checks for library functions.
AC_FUNC_MALLOC
AC_FUNC_STRTOD
AC_CHECK_FUNCS([memset select strtol])

# Args
AC_ARG_ENABLE([debug],
              AS_HELP_STRING([--enable-debug=@<:@no|yes|full@:>@],
                             [enable debugging options]),
              [use_debug=$enableval], [use_debug=no])

AC_ARG_WITH([data-path],
	AS_HELP_STRING(
	 [--with-data-path],
	 [path to game data @<:@DATAROOTDIR/drinkduino@:>@]),
	 [data_path=$withval], [data_path=])
AS_IF([test "$data_path" = "yes"], [
  AC_ERROR([The data path must be explicitly specified])
])
AS_IF([test -z "$data_path"], [
  eval data_path="$datadir/drinkduino"
  eval data_path="$data_path"
])

AC_DEFINE_UNQUOTED([GAME_DATA_PATH], ["$data_path"],
                   [Define to the path where the games data resides])

# Flags

AC_MSG_CHECKING([whether to enable debugging options])
AS_IF([test "$use_debug" = "yes" || test "$use_debug" = "full"], [
  AC_DEFINE([ENABLE_DEBUG], 1, [Define to 1 if compiling in debug mode])
  CFLAGS="-ggdb"
], [
  AS_IF([test "$use_debug" != "no"], [
     AC_MSG_ERROR([Invalid value specified for --enable-debug])
  ])
])
AC_MSG_RESULT([$use_debug])

CFLAGS="$CFLAGS $SDL_CFLAGS"
LIBS="$LIBS $SDL_LIBS -lsqlite3"

AC_SUBST([data_path])

AC_CONFIG_FILES([Makefile src/Makefile data/Makefile data/images/Makefile data/fonts/Makefile])
AC_OUTPUT

echo
AC_MSG_NOTICE([data path:          $data_path])
AC_MSG_NOTICE([debugging options:  $use_debug])

